package com.ruoyi.project.module.parameter.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.module.parameter.service.IParameterService;
import com.ruoyi.project.module.project.service.IProjectService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * <br>
 *
 * @author 蒋カイセキ    Japan-Tokyo  18-12-11 上午7:16<br>
 * ブログ http://www.shoukaiseki.top/<br>
 * E-メール jiang28555@Gmail.com<br>
 **/
@Controller
@RequestMapping("/module/parameterImport")
public class ParameterImportController extends BaseController {


    private String prefix = "module/parameter";

    @Autowired
    private IParameterService parameterService;

    @Autowired
    private IProjectService projectService;

    @RequiresPermissions("module:parameter:view")
    @GetMapping("/copy/{uniqueId}")
    public String copy(@PathVariable("uniqueId") Long uniqueId, ModelMap mmap)
    {
        mmap.put("apiProjectnameId",uniqueId);

        return prefix + "/selectProjectToCopy";
    }

    @RequiresPermissions("module:parameter:add")
    @PostMapping("/copy")
    @Transactional
    @ResponseBody
    public AjaxResult copy(Long sourceApiProjectnameId,Long targetApiProjectnameId)
    {
        logger.debug("---------------------targetApiProjectnameId={},sourceApiProjectnameId={}",targetApiProjectnameId,sourceApiProjectnameId);
        int i = parameterService.copyParameterWithProjectId(sourceApiProjectnameId, targetApiProjectnameId);
        return toAjax(i);
    }

}
